package de.koller.worlders.engine.entity.plattform;

import de.koller.oceanFramework.math.Vec;
import de.koller.worlders.engine.entity.mo.MovingObject;
import de.koller.worlders.engine.tiles.ITile;
import de.koller.worlders.engine.tiles.data.ITileCreator;
import de.koller.worlders.engine.tiles.light.LightSource;
import de.koller.worlders.render.VisualMap;
import de.koller.worlders.render.visual.DisplayRenderObject;

public class DeathPlattform extends PlattformEffect {
	public static final int GEN_ID = 11;
	
	public static final ITileCreator GEN_INSTANCE = new ITileCreator() {
		@Override public ITile newInstance() {
			return new Plattform().addEffect( new DeathPlattform() );
		}
		
		@Override public DisplayRenderObject getIcon() { return VisualMap.deathPl; }
		@Override public String getName() { return "Todesplattform"; }
	};
	
	private LightSource lightsource;
	
	protected DeathPlattform() {}
	
	@Override
	public void init( Plattform p ) {
		super.init( p );
//		p.setTextureRep( new TextureRep( "data/tiles.png", 32*4, 0, 32, 32 ) );
		p.getTile().setVisual( VisualMap.deathPl );
			
		if( p.root == null )
			return;
		
		lightsource = p.root.getTileMap().getLight().addLightSource( 
				p.getPosition().getXi(), p.getPosition().getYi(), 0xffa00000 );
	}

	@Override
	public void release() {
		super.release();
		
		plattform.root.getTileMap().getLight().removeLightSource( lightsource );
	}
	
	@Override
	public void collision( Vec wayBefore, Vec wayAfter, MovingObject mo ) {
		super.collision( wayBefore, wayAfter, mo );
		
		if( mo.mostate.isGameplayAffected() && !mo.isDeath() )
			mo.setDeath( true );
		
		wayAfter.set( 0, 0 );
		mo.getEnergy().set( 0, 0 );
		mo.getVelocity().set( 0, 0 );
	}

}
